<template>
  <div>
    <h1>医院</h1>
    <el-form :inline="true" :model="listReq" class="demo-form-inline">
      <el-form-item label="医院名称">
        <el-input v-model="listReq.name" placeholder="医院名称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="hospitalList">
      <el-table-column label="序号" prop="hospitalId" width="120"/>
      <el-table-column label="医院名称" prop="hospitalName" :show-overflow-tooltip="true" width="150"/>
      <el-table-column label="医师人数" prop="inquiryCount" :show-overflow-tooltip="true" width="150"/>
      <el-table-column label="问诊次数" prop="doctorNum" :show-overflow-tooltip="true" width="150"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="toDepartment(scope.row.hospitalId)"
          >进入
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="listReq.pageNum"
        :page-sizes="[3, 5, 10, 20]"
        :page-size="listReq.pageSize"
        layout="sizes, prev, pager, next"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）,
//例如：import 《组件名称》 from '《组件路径》,
import {hospitalList} from "@/api/manage/doctor";
import path from "path";

export default {
  //import引入的组件需要注入到对象中才能使用"
  components: {},
  props: {},
  data() {
    //这里存放数据"
    return {
      hospitalList: [],
      loading: true,
      //分页
      listReq:{
        pageSize: 3,
        pageNum: 1,
        name: "",
      },
      total:null
    };
  },
  //计算属性 类似于data概念",
  computed: {},
  //监控data中的数据变化",
  watch: {},
  //方法集合",
  methods: {
    onSubmit(){
      this.getHospitalList();
    },
    toDepartment(hospitalId) {

      this.$router.push({path:'/manage/doctor/department',query:{hospitalId:hospitalId}})
    },
    getHospitalList() {
      hospitalList(this.listReq).then(res => {
        this.listReq.pageNum = res.data.pageNum
        this.listReq.pageSize = res.data.pageSize
        this.total = res.data.total
        this.hospitalList = res.data.list
        this.loading = false
      })
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.listReq.pageSize = val
      this.getHospitalList();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）",
  created() {
    this.getHospitalList();
  },
  //生命周期 - 挂载完成（可以访问DOM元素）",
  mounted() {
  },
  beforeCreate() {
  }, //生命周期 - 创建之前",
  beforeMount() {
  }, //生命周期 - 挂载之前",
  beforeUpdate() {
  }, //生命周期 - 更新之前",
  updated() {
  }, //生命周期 - 更新之后",
  beforeDestroy() {
  }, //生命周期 - 销毁之前",
  destroyed() {
  }, //生命周期 - 销毁完成",
  activated() {
  } //如果页面有keep-alive缓存功能，这个函数会触发",
};
</script>
<style scoped>
h1 {
  text-align: center;
  margin-bottom: 20px; /* 添加一些间距 */
}

/* 使表单查询按钮居中 */
.demo-form-inline {
  display: flex;
  justify-content: center;
  margin-bottom: 20px; /* 添加一些间距 */
}
</style>
